import { GBitmap } from "../controls/GBitmap";
import { UICompomentPool } from "../utils/UICompomentPool";
import { ScaleBitmap } from "../display/ScaleBitmap";
import { Library } from "./Library";
//class GlobalClass

export class GlobalClass {
  public static hasRes(arg1: string): Boolean {
    return GlobalClass.libaray.hasDefinition(arg1);
  }

  public static getInstance(arg1: string) {
    var loc1 = GlobalClass.libaray.getDefinition(arg1);
    return new loc1();
  }

  public static getClass(arg1: string) {
    return GlobalClass.libaray.getDefinition(arg1);
  }

  public static getBitmapData(
    arg1: string
  ): Object /* flash.display.BitmapData */ {
    if (!(arg1 in GlobalClass._bitmapdataMap)) {
      GlobalClass._bitmapdataMap[arg1] = GlobalClass.getBitmapdataImpl(arg1);
    }
    return GlobalClass._bitmapdataMap[arg1];
  }

  public static getBitmap(arg1: string): GBitmap {
    var loc2 = null;
    var loc1 = GlobalClass.getBitmapData(arg1);
    if (loc1 != null) {
      loc2 = UICompomentPool.getUICompoment(GBitmap) as GBitmap;
      loc2.bitmapData = loc1;
      return loc2;
    }
    return null;
  }

  public static getScaleBitmap(
    arg1: string,
    arg2: Object /* flash.geom.Rectangle */ = null
  ): ScaleBitmap {
    var loc2 = null;
    var loc1 = GlobalClass.getBitmapData(arg1);
    if (loc1 != null) {
      (loc2 = UICompomentPool.getUICompoment(
        ScaleBitmap
      ) as ScaleBitmap).bitmapData = loc1.clone();
      loc2.createDisposeChildren();
      loc2.scale9Grid = arg2;
      return loc2;
    }
    return null;
  }

  /* internal  */ static getBitmapdataImpl(
    arg1: string
  ): Object /* flash.display.BitmapData */ {
    var loc1 = GlobalClass.getClass(arg1);
    if (loc1 != null) {
      return new loc1(0, 0) as Object /* flash.display.BitmapData */;
    }
    return null;
  }

  public static /* var */ libaray: Library;

  private static /* var */ _bitmapdataMap: Map<
    any,
    any
  > /* flash.utils.Dictionary */;
}

GlobalClass.libaray = new Library("global");
GlobalClass._bitmapdataMap = new Map<any, any> /* flash.utils.Dictionary */();
